<?php
class Control_model extends CI_Model
{
    private $_table = 'order';
    function __construct()
    {
        parent::__construct();
    }
    function add($data){
        return $this->db->insert($this->_table,$data);
    }
    function table_list($where){
        $this->db->select('table.*,order.drink_id as busy');
        $this->db->from('table');
        $this->db->join('order','table.id=order.table_id','left');
        $this->db->group_by('table.id');
        $this->db->where($where);
        return $this->db->get()->result_array();
    }
    function get_bill($where){
        $this->db->select('*');
        $this->db->from($this->_table);
        $this->db->join('drink','drink.id = order.drink_id','inner');
        $this->db->where($where);
        return $this->db->get()->result_array();
    }
    function check_duplication($where){
        $q = $this->db->get_where($this->_table,$where);
        return $q->num_rows();
    }
    function update_duplication($quantum,$user_id,$table_id,$drink_id){
        $q = "UPDATE `".$this->_table."` SET quantum = quantum + ".$quantum." WHERE drink_id = '".$drink_id."' && user_id = '".$user_id."' && table_id = '".$table_id."'";
        return $this->db->query($q);
    }
}